package org.dromara.common.alarm.utils;

import com.cloud.alarm.dinger.DingerSender;
import com.cloud.alarm.dinger.core.entity.DingerRequest;
import com.cloud.alarm.dinger.core.entity.DingerResponse;
import com.cloud.alarm.dinger.core.entity.enums.MessageSubType;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.utils.SpringUtils;

/**
 * 机器人告警工具类
 */
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AlarmUtil {

    private static final DingerSender DINGER_SENDER = SpringUtils.getBean(DingerSender.class);

    /**
     * 发送机器人Text文本消息
     *
     * @author: zhou shuai
     * @date: 2024/6/19 1:05
     * @param: dingerRequest
     * @return: com.cloud.alarm.dinger.core.entity.DingerResponse
     */
    public static DingerResponse send(DingerRequest dingerRequest) {
        try {
            return DINGER_SENDER.send(MessageSubType.TEXT, dingerRequest);
        } catch (Exception e) {
            log.error("发送机器人Text文本消息失败:", e);
        }
        return null;
    }

    /**
     * 发送机器人消息
     *
     * @author: zhou shuai
     * @date: 2024/6/19 1:05
     * @param: messageSubType
     * @param: dingerRequest
     * @return: com.cloud.alarm.dinger.core.entity.DingerResponse
     */
    public static DingerResponse send(MessageSubType messageSubType, DingerRequest dingerRequest) {
        try {
            return DINGER_SENDER.send(messageSubType, dingerRequest);
        } catch (Exception e) {
            log.error("发送机器人消息失败:", e);
        }
        return null;
    }

}
